﻿using Turnable.Places;

namespace Turnable.Layouts;

public record Location(Coordinate X, Coordinate Y)
{
    internal int DistanceTo(Location end, bool allowDiagonal) =>
        allowDiagonal ? Math.Max(Math.Abs(X - end.X), Math.Abs(Y - end.Y)) : Math.Abs(X - end.X) + Math.Abs(Y - end.Y);

    public Location LocationAt(Direction direction, int distance) => direction switch
    {
        Direction.Up => new(X, Y + distance),
        Direction.Down => new(X, Y - distance),
        Direction.Left => new(X - distance, Y),
        Direction.Right => new(X + distance, Y),
        _ => throw new ArgumentOutOfRangeException(nameof(direction), direction, null)
    };

    public override string ToString() => $"({X.Value}, {Y.Value})";
};
